#!/usr/bin/env python3
# coding:utf-8
""" 
解析请求的数据
"""
import json
from flask import Flask, request, render_template

app = Flask(__name__)


@app.route("/test/<int:idx>")
def fetch_test(idx):
    if idx == 1:
        file="1_fetch_请求url_待json数据.html"
    elif idx == 2:
        file="2_fetch_定时请求.html"
    else:
        return "unkonw test"
    return render_template(file)

count = 1
@app.route("/fetch1_url_with_json_data", methods=["GET", "POST"])
def fetch1_url_with_json_data():
    global count
    data = request.json
    print(data)
    data["status"] = "ok"
    data["code"] = 200
    data["count"] = count
    count += 1

    return json.dumps(data).encode()


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8800)
